﻿using System;
using System.ComponentModel.DataAnnotations;
using Web.Infrastructure.Models;

namespace Web.Areas.Admin.Models.Responses
{
    public class ResponseEditModel : BaseModel
    {
        public ResponseEditModel(BLL.Services.Responses.Response response)
        {
            ToModel(response, this);
        }

        public ResponseEditModel()
        {
        }

        [Display(Name = "Content")]
        [UIHint("MultilineText")]
        [StringLength(1000)]
        [Required]
        public string Content { get; set; }

        [Display(Name = "DateOfPublish")]
        [Required]
        public DateTime DateOfPublish { get; set; }

        [ScaffoldColumn(false)]
        public string DateOfPublishAsString
        {
            get
            {
                return DateOfPublish.ToShortDateString();
            }
        }

        [Required]
        [UIHint("select")]
        [Display(Name = "Book")]
        [Range(1, int.MaxValue, ErrorMessage = "Please select book.")]
        public int BookId { get; set; }

        [Required]
        [Range(1, int.MaxValue, ErrorMessage = "Please select user.")]
        [UIHint("select")]
        [Display(Name = "User")]
        public int UserId { get; set; }

        public static explicit operator BLL.Services.Responses.Response(ResponseEditModel model)
        {
            var response = new BLL.Services.Responses.Response();
            ToEntity(model, response);
            return response;
        }
    }
}